<!--
 * @Author: 许警 11378748333@
 * @Date: 2025-03-19 15:28:03
 * @LastEditors: 许警 11378748333@
 * @LastEditTime: 2025-05-22 10:23:40
 * @FilePath: /hsxlsystem/src/components/common/inputModal.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <a-modal :width="600" v-model:visible="visible" :title="title" @ok="handleOk" @cancel="handleCancel" :closable="false">
    <a-form ref="reasonRef" :model="reasonForm" :rules="rules">
      <a-form-item :label="label" name="value">
        <a-textarea v-if="type == 'textarea'" v-model:value="reasonForm.value"></a-textarea>
        <a-input v-if="type == 'input'" v-model:value="reasonForm.value" placeholder="请输入"></a-input>
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script setup>
import { computed, defineExpose, onMounted, ref, reactive } from 'vue'

// 假设 selectOrderDetailOrganByNumber 是一个从其他地方导入的函数
// import { selectOrderDetailOrganByNumber } from './somePath';

const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  title: {
    default: null
  },
  number: {
    default: null
  },
  label: {
    default: null
  },
  type: {
    default: 'textarea'
  }
})
const rules = {
  value: [
    {
      required: true,
      message: '请填写!',
      trigger: 'blur'
    }
  ]
}
const visible = ref(false)
const reasonRef = ref('')
const reasonForm = reactive({
  value: ''
})
const emit = defineEmits(['close', 'ok'])

const handleCancel = () => {
  reasonForm.value = ''
  visible.value = false
}
const handleOk = () => {
  reasonRef.value.validate().then(async () => {
    emit('ok', reasonForm.value)
    handleCancel()
  })
}

// 注意：直接在 setup 函数中调用异步函数 init() 可能会导致在 DOM 挂载前执行
// 如果你需要在组件挂载后执行某些操作，请使用 onMounted

const showModal = value => {
  visible.value = true
  if (value) {
    reasonForm.value = value
  }
}
defineExpose({
  showModal
})
</script>
<style scoped>
.ant-form-item {
  margin-bottom: 10px;
}
</style>
